var doing;
var path;
$(document).ready(function(){
	
	initParam();
	
	initEvent();
});

function initParam(){
	doing = false;
	path = $("#path").val();
}

function initEvent(){
	// 添加购物车
	//$(".addcart").live("click",addCart);
}

function addCart(){
	if(doing){
		return;
	}
	doing = true;
	var data = $(".item").attr("data");
	var datas = data.split("_");
	var merchandiseBarcode = datas[2];
	var shopId = datas[1];
	
	var url = path + "/cart/add/"+shopId+"/"+merchandiseBarcode;
	$.ajax({
	    type: 'POST',
	    url: url ,
	    dataType: "text",
	    success:function(result) {
	    	var content = "";
        	switch (result) {
			case 'YYK-10000':
				window.location.href=path+"/cart/index/"+shopId;
				break;
			case 'YYK-20002':
				content = "每箱重量超出限额";
				break;
			case 'YYK-20003':
				content = "每箱数量超出限额";
				break;
			case 'YYK-20004':
				content = "每箱价钱超出限额";
				break;
			default:
				content = "系统繁忙，请稍候重试";
				break;
			}
        	// 显示消息
        	if(content != ""){
        		$.dialog({
    				content : content,
    				title : '温馨提示',
    				time:2000,
    				lock : true
    			});
        	}
	    	
	    	doing = false;
	    } ,error:function(){
	    	alert("add cart failed.");
	    	doing = false;
	    }
	});
}
		